package cn.zero.org.service.impl;

import cn.zero.basic.utils.PageList;
import cn.zero.org.domain.Department;
import cn.zero.org.mapper.DepartmentMapper;
import cn.zero.org.query.DepartmentQuery;
import cn.zero.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
* @Description: TODO
* @Author: Tang
* @Version: 1.0
* @Date:  2022/6/21 16:54
*/
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartemtServiceImpl implements IDepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    /**
    * @Title: loadAll
    * @Description: TODO
    * @Author: Tang
    * @Version: 1.0
    * @Date:  2022/6/21 16:55
    * @Parameters: []
    * @Return java.util.List<cn.zero.org.domain.Department>
    */
    @Override
    public List<Department> loadAll() {
        return departmentMapper.loadAll();
    }

    /**
    * @Title: loadById
    * @Description: TODO
    * @Author: Tang
    * @Version: 1.0
    * @Date:  2022/6/21 16:55
    * @Parameters: [java.lang.Long]
    * @Return cn.zero.org.domain.Department
    */
    @Override
    public Department loadById(Long id) {
        return departmentMapper.loadById(id);
    }

    /**
    * @Title: remove
    * @Description: TODO
    * @Author: Tang
    * @Version: 1.0
    * @Date:  2022/6/21 16:55
    * @Parameters: [java.lang.Long]
    * @Return void
    */
    @Override
    @Transactional
    public void remove(Long id) {
        departmentMapper.remove(id);
    }

    /**
    * @Title: save
    * @Description: TODO
    * @Author: Tang
    * @Version: 1.0
    * @Date:  2022/6/21 16:55
    * @Parameters: [cn.zero.org.domain.Department]
    * @Return void
    */
    @Override
    @Transactional
    public void save(Department department) {
        departmentMapper.save(department);

    }
    /**
    * @Title: update
    * @Description: TODO
    * @Author: Tang
    * @Version: 1.0
    * @Date:  2022/6/21 16:55
    * @Parameters: [cn.zero.org.domain.Department]
    * @Return void
    */
    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);
    }

    /**
    * @Title: queryData
    * @Description: TODO
    * @Author: Tang
    * @Version: 1.0
    * @Date:  2022/6/21 16:55
    * @Parameters: [cn.zero.org.query.DepartmentQuery]
    * @Return cn.zero.basic.utils.PageList<cn.zero.org.domain.Department>
    */
    @Override
    public PageList<Department> queryData(DepartmentQuery departmentQuery) {
        //当前页面总条数
        Integer total = departmentMapper.queryCount(departmentQuery);
        //当前页面数据
        List<Department> rows = departmentMapper.queryData(departmentQuery);
        return new PageList<>(total,rows);
    }
}
